package com.zpkj.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

/**
 * Created  on 2018/5/28.
 */
@Service
public class ComputerRibbonService {

	@Autowired
	private RestTemplate restTemplate;

	@HystrixCommand(fallbackMethod = "computerFallback")
	public String add(Integer a, Integer b) {
		String url = "http://TRAFFICCHAIN-MICRO-SERVICES-UC/add?a=" + a + "&b=" + b;
		String response = restTemplate.getForEntity(url, String.class).getBody();
		return response;
	}

	/**
	 * fallback method wasn't found
	 * 备用方法 和 原方法 的参数个数，类型不同造成的
	 */
	public String computerFallback(Integer a, Integer b) {
		return "ribbon invoke error";
	}
}
